package Java0309.Java0310;

import java.util.Scanner;

public class PrintRectangle {
    public static void main(String[] args) {
        //要求：输出空心矩形，矩形的高和宽用户输入， 必须都大于等于3，否则要求重新输入；
        Scanner scan = new Scanner(System.in);
        //高
        int high = 0;
        //宽
        int width = 0;
        System.out.println("请输入矩形的高和宽：");
        while (true) {
            high = scan.nextInt();
            width = scan.nextInt();
            if (high > 2 && width > 2) {
                break;
            }
            System.out.println("错误，请重新输入：");
        }
        //外层循环控制行数
        for (int i = 0; i < high; i++) {
            //里层循环控制列数
            for (int j = 0; j < width; j++) {
                if (i == 0) {
                    System.out.print("*");
                } else if (i == high - 1) {
                    System.out.print("*");
                } else if (j == 0 || j == width - 1) {
                    System.out.print("*");
                } else {
                    System.out.print(" ");
                }
            }
            //打印一行结束换行
            System.out.println();
        }
    }
}
